#include "div_repeat_u32.h"
#include "rtwtypes.h"

uint32_T div_repeat_u32(uint32_T numerator, uint32_T denominator, uint32_T
  nRepeatSub)
{
  uint32_T iRepeatSub;
  uint32_T quotient;
  if (denominator == 0U) {
    quotient = MAX_uint32_T;
  } else {
    uint32_T localNumerator;
    quotient = numerator / denominator;
    localNumerator = numerator % denominator;
    for (iRepeatSub = 0U; iRepeatSub < nRepeatSub; iRepeatSub++) {
      boolean_T numeratorExtraBit;
      numeratorExtraBit = (localNumerator >= 2147483648U);
      localNumerator <<= 1U;
      quotient <<= 1U;
      if (numeratorExtraBit || (localNumerator >= denominator)) {
        quotient++;
        localNumerator -= denominator;
      }
    }
  }

  return quotient;
}
